﻿/*
   这个表可以从server的t_brokenaddr得到，每天自动获取,
 * 可以算出在某个经纪公司产生了多少的盈利或返还等
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
/*
    2012-2-17 David检查正常
 */
namespace BenefitHelper.Sys
{
    /// <summary>
    /// 经纪公司
    /// </summary>
    public class Broker
    {
        [Key]
        public int Id { get; set; }
        /// <summary>
        /// 经纪公司名称
        /// </summary>
        public string BrokerName { get; set; }
        /// <summary>
        /// 是否被删除
        /// </summary>
        public bool IsDeleted { get; set; }
        /// <summary>
        /// 经纪公司代码
        /// </summary>
        public string BrokerId { get; set; }

        /// <summary>
        /// 初始化经纪公司
        /// </summary>
        public void InitBrokers(DB.DBManager db)
        {
            List<Data.ServerData.T_BrokenAddr> brokers = new Data.ServerData.T_BrokenAddr().GetList();
            foreach (Data.ServerData.T_BrokenAddr addr in brokers)
            {
                var query = from t in db.Broker where t.BrokerId.Equals(addr.BrokenId) select t;
                if (query.Count() == 0)
                {
                    Sys.Broker broker = new Sys.Broker();
                    broker.BrokerId = addr.BrokenId;
                    broker.BrokerName = addr.BrokenName;
                    broker.IsDeleted = false;
                    db.Broker.Add(broker);
                }
            }
        }
        /// <summary>
        /// 获取所有经纪公司
        /// </summary>
        /// <param name="db"></param>
        /// <returns></returns>
        public List<Broker> GetList(DB.DBManager db)
        {
            return db.Broker.ToList();
        }
    }
}